package service.sys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.BaseMapper;
import com.common.BaseService;
import com.common.CommonUtil;

import mapper.sys.RoleUserMapper;

@Service
@Transactional
public class RoleUserServiceImpl <T> extends BaseService<T>{
	@Autowired
	private RoleUserMapper roleUserMapper;

	public List<Map> getByRoleid(String uid){
		List<Map> m = roleUserMapper.getByRoleid(uid);
		return m;
	}

	public List<Map> getByUserid(String uid){
		List<Map> m = roleUserMapper.getByUserid(uid);
		return m;
	}

	public void saveRoleFun(String roleid,String[] ids){
		roleUserMapper.delRoleUser(roleid);
		List<Map> list = new ArrayList<>();
		if(ids.length>0){
			for(String s : ids){
				if(CommonUtil.isNullObject(s))continue;
				Map m = new HashMap();
				m.put("id", UUID.randomUUID().toString());
				m.put("roleid", roleid);
				m.put("userid", s);
				list.add(m);
			}
			if(list.size()>0)
				roleUserMapper.saveRoleUser(list);
		}
	}

	public void saveRoleFun(String roleid,String id){
		List<Map> list = new ArrayList<>();

		Map m = new HashMap();
		m.put("id", UUID.randomUUID().toString());
		m.put("roleid", roleid);
		m.put("userid", id);
		list.add(m);
		roleUserMapper.saveRoleUser(list);
	}

	@Override
	public BaseMapper<T> getMapper() {
		return roleUserMapper;
	}
}
